<?php
/**
 * This file contains template tags that allow theme developers that wish to utilize
 * our portfolio posts an easy way to access portfolio meta data for a given post.
 * 
 * These abstractions allow theme developers to access meta data without the need to
 * know how the data is stored in the database.
 * 
 * @author Mike Burns
 */

/**
 * Display the client name associated with the specified portfolio post
 * 
 * Will use the current post ID (accssed through the global post object)
 * if no ID is supplied
 * 
 * @global StdObj $post A WordPress StdObj for the current post
 * @param int $post_id A post ID
 */
function cdia_the_portfolio_client( $post_id = 0 ) {
	global $post;

	if( $post_id == 0 ) {
		$post_id = $post->ID;
	}
	
	$details = get_post_meta( $post_id, CDIA_PORT_META_KEY, true );
	$client = ( isset( $details['client_name'] ) ) ? $details['client_name'] : '';

	echo $client;
}

/**
 * Display whether or not the portfolio item has a client defined
 * 
 * Will use the current post ID (accssed through the global post object)
 * if no ID is supplied
 * 
 * @global StdObj $post A WordPress StdObj for the current post
 * @param int $post_id A post ID
 */
function cdia_portfolio_has_client( $post_id = 0 ) {
	global $post;

	if( $post_id == 0 ) {
		$post_id = $post->ID;
	}
	
	$details = get_post_meta( $post_id, CDIA_PORT_META_KEY, true );

	if( isset( $details['client_name'] ) && !empty( $details['client_name'] ) ) {
		return true;
	} else {
		return false;
	}
}

/**
 * Display the year associated with the specified portfolio post
 * 
 * Will use the current post ID (accssed through the global post object)
 * if no ID is supplied
 * 
 * @global StdObj $post A WordPress StdObj for the current post
 * @param int $post_id A post ID
 */
function cdia_the_portfolio_year( $post_id = 0 ) {
	global $post;

	if( $post_id == 0 ) {
		$post_id = $post->ID;
	}
	
	$details = get_post_meta( $post->ID, CDIA_PORT_META_KEY, true );
	$completion_year = ( isset( $details['completion_year'] ) ) ? $details['completion_year'] : '';

	echo $completion_year;
}

/**
 * Display whether or not the portfolio item has a year defined
 * 
 * Will use the current post ID (accssed through the global post object)
 * if no ID is supplied
 * 
 * @global StdObj $post A WordPress StdObj for the current post
 * @param int $post_id A post ID
 */
function cdia_portfolio_has_year( $post_id = 0 ) {
	global $post;

	if( $post_id == 0 ) {
		$post_id = $post->ID;
	}
	
	$details = get_post_meta( $post_id, CDIA_PORT_META_KEY, true );

	if( isset( $details['completion_year'] ) && !empty( $details['completion_year'] ) ) {
		return true;
	} else {
		return false;
	}
}

/**
 * Display the site URL associated with the specified portfolio post
 * 
 * Will use the current post ID (accssed through the global post object)
 * if no ID is supplied
 * 
 * @global StdObj $post A WordPress StdObj for the current post
 * @param int $post_id A post ID
 */
function cdia_the_portfolio_site_url( $post_id = 0 ) {
	global $post;

	if( $post_id == 0 ) {
		$post_id = $post->ID;
	}
	
	$details = get_post_meta( $post->ID, CDIA_PORT_META_KEY, true );
	$site_url = ( isset( $details['link'] ) ) ? $details['link'] : '';

	echo $site_url;
}

/**
 * Display whether or not the portfolio item has a site URL defined
 * 
 * Will use the current post ID (accssed through the global post object)
 * if no ID is supplied
 * 
 * @global StdObj $post A WordPress StdObj for the current post
 * @param int $post_id A post ID
 */
function cdia_portfolio_has_site_url( $post_id = 0 ) {
	global $post;

	if( $post_id == 0 ) {
		$post_id = $post->ID;
	}
	
	$details = get_post_meta( $post_id, CDIA_PORT_META_KEY, true );

	if( isset( $details['link'] ) && !empty( $details['link'] ) ) {
		return true;
	} else {
		return false;
	}
}

/**
 * Display the CMS associated with the specified portfolio post
 * 
 * Will use the current post ID (accssed through the global post object)
 * if no ID is supplied
 * 
 * @global StdObj $post A WordPress StdObj for the current post
 * @param int $post_id A post ID
 */
function cdia_the_portfolio_cms( $post_id = 0 ) {
	global $post;
	
	if( $post_id == 0 ) {
		$post_id = $post->ID;
	}	
	
	$details = get_post_meta( $post->ID, CDIA_PORT_META_KEY, true );
	$cms = ( isset( $details['cms'] ) ) ? $details['cms'] : '';

	echo $cms;
}

/**
 * Display whether or not the portfolio item has a CMS defined
 * 
 * Will use the current post ID (accssed through the global post object)
 * if no ID is supplied
 * 
 * @global StdObj $post A WordPress StdObj for the current post
 * @param int $post_id A post ID
 */
function cdia_portfolio_has_cms( $post_id = 0 ) {
	global $post;

	if( $post_id == 0 ) {
		$post_id = $post->ID;
	}
	
	$details = get_post_meta( $post_id, CDIA_PORT_META_KEY, true );

	if( isset( $details['cms'] ) && !empty( $details['cms'] ) ) {
		return true;
	} else {
		return false;
	}
}

?>